﻿using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;

public class AssetsManager {

    #region SingleTon

    public static readonly AssetsManager instance = new AssetsManager();

    private AssetsManager() {
        assets = new Dictionary<string, object>();
    }

    #endregion

    #region AssetsManager

    private Dictionary<string, object> assets;

    public object GetAssetByName(string name)
    {
        //如果没有有该资源，则需要先加载
        if (!assets.ContainsKey(name))
        {
            //获取到字段信息
            FieldInfo info = typeof(AssetsPath).GetField(name + "AssetsPath", BindingFlags.NonPublic | BindingFlags.Static);
            //获取字段的值
            string path = info.GetValue(null).ToString();
            //没有该资源则需要先加载
            object obj = Resources.Load(path);
            assets.Add(name, obj);
        }

        return assets[name];
    }

    #endregion
}

public class AssetsPath
{
    private const string CubeAssetsPath = "Cube";
}
